function [theta] = softMaxLearn(x,s)

y = s; % jst changing the name since that what i used below, but wanted to be clear in the function signature

% x is the features matrix (m rows and (n-1) columns)
% y (and s) is the vector of desired (groundTruth) states
nStates = 6;
m = size(x,1);
X = horzcat(ones(m,1),x);
alpha = 1;
n = size(X,2);
theta = zeros(nStates,n);
theta_old = theta;
TOLERANCE = 5;

while(true)
    for i=1:m
        xi = X(i,:);
        yi = y(i);
        u = exp(theta*xi');
        su = sum(u,1);
        v = u/su;
        v(yi) = v(yi)+1;
        grad = v*xi;
        theta = theta + alpha*grad
    end
    change = theta - theta_old;
    squaredChange = sum(sum(change.*change))
    if (squaredChange < TOLERANCE)
        break;
    end
end

end
